const { Tab } = require('../../assets/libs/zanui/index');

var app = getApp();
Page(Object.assign({}, Tab, {
  data: {
		cdnUrl: '',
		isHidden: true,
	
		/* 自定义导航栏参数 */
		loading: false,
		color: '#FFFFFF',
		background: '#FFFFFF',
		show: true,
		animated: false,
		back: true,
		title: "商品详情",
		
		productDetail: {}
  },
	/* 获取商品信息 */
	productDetail: function(id){
		var that = this;
		app.request('/addons/cms/wxapp.shop/productDetail', {id: id}, function (data, ret) {//获取地址信息
		  that.setData({
				productDetail: data
		  });
		}, function (data, ret) {
			app.error(ret.msg);
			setTimeout(function(){
				wx.navigateBack({});
			},2000)
		});
		
	},
	/* 兑换商品 */
	orderProduct: function(){
		var that = this;
		app.request('/addons/cms/wxapp.shop/orderProduct', {id: that.data.productDetail.id}, function (data, ret) {//获取地址信息
			// return false;
		  wx.navigateTo({
		  	url: '/page/integral_exchange_msg/index?code=1&msg='+ret.msg+'&id='+data.id
		  });
		}, function (data, ret) {
			// return false;
			wx.navigateTo({
				url: '/page/integral_exchange_msg/index?code=0&msg='+ret.msg+'&id=0'
			});
		});
		
	},
  onLoad: function (e) {
		if (Object.keys(e).length === 0) {
		    app.error('参数错误');
		    setTimeout(function(){
		    	wx.navigateBack({});
		    },1000)
				return false;
		}
		var id = e.id;
    var that = this;
		that.productDetail(id);
		that.setData({
			cdnUrl: app.cdnUrl,
		});
  },
  onShareAppMessage: function () {
    return {
      title: '',
      desc: '',
      path: '/page/index/index'
    }
  },
  /* 弹窗 */
  showMd: function(e) {
		var that = this;
		this.setData({
			isHidden: false,//显示模态框，
		})
  },
  hiddenMd: function() {
		this.setData({
				isHidden: true//隐藏模态框
		})
  },
}))
